<template>
  <div id="gradelist"> 

          <el-table :data="datalist" style="width: 100%" :height="dtheight" :header-cell-style="{background:'#4F81BC',color:'white'}"
           :row-class-name="tableRowClassName"  :border="true">
               
                <el-table-column label="类别"  align='center' >                   
                    <template slot-scope="scope">                   
                        <span >{{ scope.row.title }}</span>
                    </template>
                </el-table-column>   
                <el-table-column label="Logo"  align='center' >                   
                    <template slot-scope="scope">                   
                       <img  style="width: 30px; height: 30px" :src="urlimg + scope.row.logo" /> 
                    </template>
                </el-table-column>
                <el-table-column label="类别奖励 "  align='center' >                   
                    <template slot-scope="scope">                   
                        <span >{{ scope.row.reward_scale }}</span>
                    </template>
                </el-table-column>
                 <!-- <el-table-column label="奖励天数 "  align='center' >                   
                    <template slot-scope="scope">                   
                        <span >{{ scope.row.reward_day }}</span>
                    </template>
                </el-table-column>
                 <el-table-column label="分享奖励天数"  align='center' >                   
                    <template slot-scope="scope">                   
                        <span >{{ scope.row.extra_person_day_number }}</span>
                    </template>
                </el-table-column> -->
                <el-table-column label="团队人数"  align='center' >                   
                    <template slot-scope="scope">                   
                        <span >{{ scope.row.need_person_number }}</span>
                    </template>
                </el-table-column>
                 <el-table-column label="团队标的等级"  align='center' >                   
                    <template slot-scope="scope">                   
                        <span v-if="scope.row.need_person_grade != null" >{{ scope.row.need_person_grade.title }}</span>
                    </template>
                </el-table-column>
                 <el-table-column label="好友人数"  align='center' >                   
                    <template slot-scope="scope">                   
                        <span >{{ scope.row.need_direct_person_number }}</span>
                    </template>
                </el-table-column>
                 <el-table-column label="好友标的等级"  align='center' >                   
                    <template slot-scope="scope">                   
                        <span v-if="scope.row.need_direct_person_grade != null">{{ scope.row.need_direct_person_grade.title }}</span>
                    </template>
                </el-table-column>
                 <el-table-column label="经验值"  align='center' >                   
                    <template slot-scope="scope">                   
                        <span >{{ scope.row.need_experience }}</span>
                    </template>
                </el-table-column>
                 <el-table-column label="是否开启"  align='center' >                   
                    <template slot-scope="scope">                   
                        <span v-if="scope.row.hide == 0">开启</span>
                        <span v-if="scope.row.hide == 1">关闭</span>
                    </template>
                </el-table-column>

                 <el-table-column label="操作" align='center' width="150px">
                    <template slot-scope="scope"> 
                        <el-button size="mini"  type="primary"  plain @click="xg_but(scope.row)">修改</el-button> 
                    </template>
                </el-table-column>        

  
            </el-table>  


            
      <!-- 修改 -->
    <el-dialog title="修改" :visible.sync="xg_mtk"  width="600px">
        <div style="width:100%;"> 


        <el-form ref="form"   label-width="120px" style="width:100%;">
    
              <el-row>
                     <el-col :span="12">
                          <el-form-item label="类别">
                             <el-input v-model="mtk_form.title" placeholder="类别" ></el-input>
                         </el-form-item>       
                     </el-col>
                      <el-col :span="12">
                        <el-form-item label="类别奖励">
                          <el-input v-model="mtk_form.reward_scale" placeholder="类别奖励" ></el-input>
                        </el-form-item>                                  
                      </el-col>
                 </el-row>

                 <!-- <el-row>
                     <el-col :span="12">
                          <el-form-item label="奖励天数">
                             <el-input v-model="mtk_form.reward_day" placeholder="奖励天数" ></el-input>
                         </el-form-item>       
                     </el-col>
                      <el-col :span="12">
                        <el-form-item label="分享奖励天数">
                          <el-input v-model="mtk_form.extra_person_day_number" placeholder="分享奖励天数" ></el-input>
                        </el-form-item>                                  
                      </el-col>
                 </el-row> -->

                 <el-row>
                     <el-col :span="12">
                          <el-form-item label="团队人数">
                             <el-input v-model="mtk_form.need_person_number" placeholder="团队人数" ></el-input>
                         </el-form-item>       
                     </el-col>
                     <el-col :span="12">
                       <el-form-item label="团队标的等级">
                            <el-select  v-model="mtk_form.need_person_grade_id"   placeholder="团队标的等级" style="width:100%;">
                                <el-option  v-for="(item,index) in type_data" :key="index" :label="item.title" :value="item.grade_id"></el-option>
                            </el-select>
                     </el-form-item>  
                      </el-col>
                 </el-row>

                  <el-row>
                     <el-col :span="12">
                          <el-form-item label="好友人数">
                             <el-input v-model="mtk_form.need_direct_person_number" placeholder="好友人数" ></el-input>
                         </el-form-item>       
                     </el-col>
                      <el-col :span="12">
                         <el-form-item label="好友标的等级">
                                <el-select  v-model="mtk_form.need_direct_person_grade_id"   placeholder="好友标的等级" style="width:100%;">
                                    <el-option  v-for="(item,index) in type_data" :key="index" :label="item.title" :value="item.grade_id"></el-option>
                                </el-select>
                          </el-form-item>                                   
                      </el-col>
                 </el-row>


                  <el-row>
                     <el-col :span="12">
                          <el-form-item label="经验值">
                             <el-input v-model="mtk_form.need_experience" placeholder="经验值" ></el-input>
                         </el-form-item>       
                     </el-col>
                      <el-col :span="12">
                         <!-- <el-form-item label="是否开启">
                                <el-select  v-model="mtk_form.select_num"   placeholder="是否开启" style="width:100%;">
                                    <el-option  v-for="(item,index) in select_data" :key="index" :label="item.name" :value="item.id"></el-option>
                                </el-select>
                          </el-form-item>                                    -->
                      </el-col>
                 </el-row>

                 <el-row style="width:100%;">
                     <el-col :span="12">
                        <el-form-item label="Logo">
                            <el-upload 
                                  action="uploadUrl"  
                                  :show-file-list="false"   
                                  :before-upload="beforeupload"
                                  :http-request="ImgUploadSectionFile">
                                  <div class="avatar-uploader">
                                      <img v-if="pic_form.head_img"  :src="pic_form.head_img" class="avatar">
                                      <i v-else class="el-icon-plus avatar-uploader-icon"></i>
                                  </div>
                            </el-upload>
                         </el-form-item>       
                     </el-col> 

                </el-row> 

            <div style="text-align: center;width:50%;margin:auto;">
                <el-button type="primary" class="custom_color_button" style="width:80%;" @click="xg_but_qr">确认</el-button>
            </div>
         </el-form>
        </div> 
    </el-dialog>



   



   </div>
</template>

<script>

export default {
   name: 'gradelist',
   props:{
      datalist:{  
        //type:Array,
       default:()=>[]
     },
  },
  data () {
    return {
        dtheight:'500',  //窗口高度
         mtk_form:{
            title:'',
            reward_scale:'',
            reward_day:'',
            extra_person_day_number:'',
            need_person_number:'',
            need_person_grade_id:'',
            need_direct_person_number:'',
            need_direct_person_grade_id:'',
            need_experience:'',
            select_num:0,
        },
        select_data:[{"id":1,"name":"关闭"},{"id":0,"name":"开启"}],
         type_data:[],
        xg_mtk:false,
        my_id:'',
        pic_form:{
           head_img:'',
           upfile:'',
        },
    }
  },
   components:{

  },
  created(){
     this.dtheight = window.innerHeight - 240
       this.type_fun()
  },
  mounted (){
    
  },
  methods: {
    type_fun(){     
           this.post("/user_grade/optionOfGrade", {
	        }).then(res => {
            //this.datalist = res.result
            this.type_data = res.result
            //console.log(res)
         })
    },
    xg_but(row){
        this.my_id = row.grade_id
        this.mtk_form.title = row.title
        this.mtk_form.reward_scale = row.reward_scale
        this.mtk_form.reward_day = row.reward_day
        this.mtk_form.extra_person_day_number = row.extra_person_day_number
        this.mtk_form.need_person_number = row.need_person_number
        this.pic_form.head_img = this.urlimg + row.logo
        // this.mtk_form.need_person_grade_id = row.need_person_grade.grade_id
        if(row.need_person_grade == null){
            this.mtk_form.need_person_grade_id = ''
        }else{
            this.mtk_form.need_person_grade_id = row.need_person_grade.grade_id
        }
        this.mtk_form.need_direct_person_number = row.need_direct_person_number
        // this.mtk_form.need_direct_person_grade_id = row.need_direct_person_grade.grade_id
        if(row.need_direct_person_grade == null){
            this.mtk_form.need_direct_person_grade_id = ''
        }else{
            this.mtk_form.need_direct_person_grade_id = row.need_direct_person_grade.grade_id
        }

        this.mtk_form.need_experience = row.need_experience
        this.mtk_form.select_num = row.hide
        this.xg_mtk = true
        
    },
    xg_but_qr(){
        this.post("/user_grade/update", {
              title:this.mtk_form.title,
              reward_scale:this.mtk_form.reward_scale,
              reward_day:this.mtk_form.reward_day,
              extra_person_day_number:this.mtk_form.extra_person_day_number,
              need_person_number:this.mtk_form.need_person_number,
              need_person_grade_id:this.mtk_form.need_person_grade_id,
              need_direct_person_number:this.mtk_form.need_direct_person_number,
              need_direct_person_grade_id:this.mtk_form.need_direct_person_grade_id,
              need_experience:this.mtk_form.need_experience,
              hide:this.mtk_form.select_num,
              grade_id:this.my_id,
              logo:this.pic_form.upfile
          }).then(res => {

              if(res.error_code == 0){
              this.open1(res.result,'success')  //提示框
              this.$emit('up_list_fun')
              this.xg_mtk = false
              }else {
              this.open1(res.message,'warning')
          }

        })
    },
    beforeupload(file){   //重新写入上穿 需要点击确认上传与表单一起提交
           if(this.upimglx(file) == false){  //判断是否为fales
              this.upimglxtitle()  //执行弹出错误             
              return false
            }  
            var windowURL = window.URL || window.webkitURL;               
            this.pic_form.head_img=windowURL.createObjectURL(file);             
            
            this.upimgpost("/image/uploadMultiple",file).then(res => {
              console.log(res.result.url )
               this.pic_form.upfile = res.result.url    
            })

            return false;
     },
      ImgUploadSectionFile(param){//图片上传    
      },

  }
}
</script>


<style scoped>
.avatar-uploader  {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
  }
  .avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 150px;
    height: 150px;
    line-height: 150px;
    text-align: center;
  }
  .avatar {
    width: 150px;
    height: 150px;
    display: block;
  }
</style>